package com.wdciti.sccp.iot.springvertx.protocols.tcp.ext;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.vertx.core.impl.CloseFuture;
import io.vertx.core.impl.VertxInternal;
import io.vertx.core.net.NetClientOptions;
import io.vertx.core.net.impl.NetClientImpl;

/**
 * @author by early
 */
public class FrameNetClientImpl extends NetClientImpl {

    private final ChannelHandler channelHandler;

    public FrameNetClientImpl(VertxInternal vertx,
                              NetClientOptions options,
                              CloseFuture closeFuture,
                              ByteToMessageDecoder decoder) {
        super(vertx, vertx.metricsSPI() != null ? vertx.metricsSPI().createNetClientMetrics(options) : null, options, closeFuture);
        this.channelHandler = decoder;
    }

    @Override
    public void initChannel(ChannelPipeline pipeline) {
        super.initChannel(pipeline);
        if (channelHandler != null) {
            pipeline.addLast(channelHandler);
        }
    }

}
